package com.huya.controller.user;

import com.huya.common.result.PageResult;
import com.huya.common.result.Result;
import com.huya.pojo.dto.KnowledgeDTO;
import com.huya.pojo.dto.KnowledgePageQueryDTO;
import com.huya.pojo.entity.Knowledge;
import com.huya.service.KnowledgeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userKnowledgeController")
@RequestMapping("/user/knowledge")
@Slf4j
public class KnowledgeController {

    @Autowired
    private KnowledgeService knowledgeService;

    /**
     * 分页查询
     * @param knowledgePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page(KnowledgePageQueryDTO knowledgePageQueryDTO){
        log.info("knowledgePageQueryDTO: {}", knowledgePageQueryDTO);
        PageResult pageResult = knowledgeService.pageQuery(knowledgePageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<Knowledge>getById(@PathVariable Long id) {
        log.info("getById: {}", id);
        Knowledge knowledge = knowledgeService.getById(id);
        return Result.success(knowledge);
    }
}
